import express, {Request, Response} from "express";
import {fileAddService, fileDelService, fileListService} from "../service/fileService";
import {flowDelService, flowListService, flowViewService} from "../service/flowService";
const router = express.Router()
/*
* parentFileUID: string, fileName: string, type: string, token: string, state: string
* */
router.post('/add/folder',  async (req: Request, res: Response) => {
    const token = req.headers[process.env.NODE_MANAGE_TOKEN as string] as string
    const { fileName, type, state, parentFileUID } = req.body
    await fileAddService(res, fileName, type, token, state, parentFileUID)
})
/*
* @param parentFileUID string
* */
router.post('/list',  async (req: Request, res: Response) => {
    const token = req.headers[process.env.NODE_MANAGE_TOKEN as string] as string
    const { fileUID } = req.body
    await fileListService(res, token, fileUID)
})

/*
* @param fileUIDList Array<string> 文件UID
* */
router.post('/del', async (req: Request, res: Response) => {
    const { fileUIDList } = req.body
    await fileDelService(res, fileUIDList)
})

router.post('/flowList',  async (req: Request, res: Response) => {
    await flowListService(res, req.headers[process.env.NODE_MANAGE_TOKEN as string] as string)
})

router.post('/flow/view', async (req: Request, res: Response) => {
    const { flowUID } = req.body
    await flowViewService(res, flowUID)
})

router.post('/flow/del', async (req: Request, res: Response) => {
    const { flowUID, path } = req.body
    await flowDelService(res, flowUID, path)
})

export default router